﻿using System;
using System.Collections.Specialized;
using System.Data;
using System.Globalization;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

using BizElements.Core;
using BizElements.BusinessLayer;

namespace BizElements.Web
{
    /// <summary>Provides webform context logic.</summary>
    public interface IWebFormContextManager
    {
        /// <summary>Builds URL based on data provided in the context.</summary>
        /// <param name="ctx">Webform context.</param>
        string BuildUrl(WebFormContext ctx);

        /// <summary>Opens URL using specified options.</summary>
        /// <param name="mode">Mode: popup or redirect.</param>
        /// <param name="url">URL.</param>
        /// <param name="size">One of predefined popup sizes.</param>
        void OpenUrl(OpenFormMode mode, string url, WindowSize size);

        /// <summary>Stores context to internal structures. Clients retrieve the context via EnsureFormContext methods.</summary>
        /// <param name="context">Context to push.</param>
        void Push(WebFormContext context);

        /// <summary>Initializes entity properties with values stored in Parameters collection.</summary>
        /// <param name="entity">Entity whose properties are parsed.</param>
        /// <param name="allParams">Name-value collection that contains entity data. Name/key matches property names.</param>
        /// <param name="criteria">Selects the group of properties to parse if the value is provided in Parameters collection.</param>
        void ParseEntityProperties(IEntity entity, NameValueCollection allParams, PropertySelection criteria);

        /// <summary>Initializes context if not alread initialized.</summary>
        /// <param name="formContext">Variable or field to initialize if not already initialized, ie. if it point to a nul reference.</param>
        /// <param name="uiWebFormContext">Hidden form field that contains XML serialized context data.</param>
        void EnsureFormContext(ref WebFormContext formContext, HiddenField uiWebFormContext);

        /// <summary>Initializes context if not alread initialized.</summary>
        /// <param name="formContext">Variable or field to initialize if not already initialized, ie. if it point to a nul reference.</param>
        /// <param name="uiWebFormContext">Hidden form field that contains XML serialized context data.</param>
        void EnsureFormContext(ref WebFormContext formContext, ITextControl uiWebFormContext);

        /// <summary>Build return URL used when current form was openned using redirect method.</summary>
        /// <param name="ctx">Webform context.</param>
        /// <param name="message">Message to be displayed in the form to which the user is redirected to.</param>
        /// <returns>URL.</returns>
        string GetReturnUrl(WebFormContext ctx, string message);

        /// <summary>Closes popup windows and executes the specified script.</summary>
        /// <param name="ctx">Webform context.</param>
        /// <param name="onBeforeCloseScript">Optional script to execute before the window is closed. Typically a script that updates window openner.</param>
        void ClosePopup(WebFormContext ctx, string onBeforeCloseScript);
    }
}
